<?php

/**
 * This is the model class for table "exhibitions".
 *
 * The followings are the available columns in table 'exhibitions':
 * @property integer $id
 * @property string $institution_name
 * @property string $contact_person
 * @property string $address
 * @property string $phone_number
 * @property string $email
 * @property string $website
 * @property string $message
 */
class Exhibitions extends CActiveRecord
{
  public $verifyCode;
  const STATUS_PENDING =  0;
  const STATUS_APPROVED = 1;
	/**
	 * Returns the static model of the specified AR class.
	 * @return Exhibitions the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'exhibitions';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
      array('modified_at', 'safe'),
			array('institution_name, address, phone_number, email, message', 'required'),
      array('email', 'email'),
      //array('phone_number',  'numerical', 'integerOnly'=>true),
			array('institution_name, contact_person, address, phone_number, email, website', 'length', 'max'=>1000),
      array('verifyCode', 'CaptchaExtendedValidator', 'allowEmpty'=>!CCaptcha::checkRequirements(), 'on' => 'frontend'),
			array('message', 'length', 'max'=>2000),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, institution_name, contact_person, address, phone_number, email, website, message', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'institution_name' => 'Institution Name',
			'contact_person' => 'Contact Person',
			'address' => 'Address',
			'phone_number' => 'Phone Number',
			'email' => 'Email',
			'website' => 'Website',
			'message' => 'Message',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('institution_name',$this->institution_name,true);
		$criteria->compare('contact_person',$this->contact_person,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('phone_number',$this->phone_number,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('website',$this->website,true);
		$criteria->compare('message',$this->message,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}

  public function getStatusName($status)
  {
    if($status == Exhibitions::STATUS_PENDING)
    {
      return "Pending";
    }
    else
    {
      return "Finished";
    }
  }
}